﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SOMSerialUpload.aspx.cs" Inherits="sWarranty.WEB.SOMSerialUpload" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<%@ Register Src="../UC/Header.ascx" TagName="Header" TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../CSS/table.css" />
    <link rel="stylesheet" type="text/css" href="../CSS/Menu.css" />
    <script src="../JS/jquery-1.8.2.js" type="text/javascript"></script>
    <script src="../JS/jquery.js" type="text/javascript"></script>
    <script src="../JS/notify.js" type="text/javascript"></script>
    <link href="../CSS/notify.css" rel="stylesheet" type="text/css" />
    <script src="../JS/jquery.tablesorter.js" type="text/javascript"></script>
    <style>
        #dropBillTo option
        {
            width: 100%;
        }
        .watermarked
        {
            background-color: #F0F8FF;
            border: 1px solid #BEBEBE;
            color: gray;
            padding: 2px 0 0 2px;
        }
    </style>
    <script type='text/javascript'>
        $(function () {
            $("table").tablesorter({ debug: false })

        });
        function openPopUp() {
            var popUrl = 'FindBill.aspx';
            var name = 'popUp';
            var appearence = 'dependent=no,menubar=no,resizable=yes,' +
                  'status=no,toolbar=no,titlebar=no,' +
                  'width=' + window.screen.availWidth * 80 / 100 + ', height=' + window.screen.availHeight * 80 / 100 + ',resizable:yes,center:yes';
            var openWindow = window.open(popUrl, name, appearence);
            openWindow.focus();
        }
        function uploadFile() {
            var filePath = $('#AsyncFileUpload1').attr('value');
            if (endsWith(filePath, '.xls') == true) {
                readExcel(filePath);
            }
            else {
                alert("System just support Excel version 2003 (*.xls) only");
            }
        }
        function endsWith(str, suffix) {
            return str.indexOf(suffix, str.length - suffix.length) !== -1;
        }
        function readExcel(path) {
            $('#imgLoading').show();
            var options = {
                type: 'POST',
                url: 'WebService1.asmx/readExcel',
                data: '{path: "' + path + '"}',
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                success: function (msg) {
                    alert(msg.d);
                    //$('#litdata').html(msg.d);
                    $('#imgLoading').hide();
                },
                error: function (msg) {
                    $('#imgLoading').hide();
                    $('#imgError').show();
                    alert(msg.d);
                }
            };
            $.ajax(options);
        }
        $(document).ready(function () {
            checkFirstVisit();

            $('#txtCell1').blur(function () {
                var value = $('#txtCell1').val();
                if (value.startsWith('09') || value.startsWith('01')) {
                    value = value.substr(1, value.length);
                    value = "+84" + value;
                    document.getElementById('txtCell1').value = value;
                }
            });

        });
        function checkFirstVisit() {
            if (document.cookie.indexOf('mycookie') == -1) {
                // cookie doesn't exist, create it now
                document.cookie = 'mycookie=1';
                $('#lblBillTo').text('-- Select --');
                $('#lblCusCode').text('-- Select Bill Code first --');

            }
            else {
                // not first visit, so alert
                //alert('You refreshed!');
                var billto = $('#txtdropBillTo').val();
                var cusCode = $('#txtlblCusCode').val();
                $('#lblBillTo').text(cusCode);
                $('#lblCusCode').text(cusCode);
                //                for (var i = document.getElementById('dropBillTo').options.length - 1; i >= 0; i--) {
                //                    if (document.getElementById('dropBillTo').options[i].value == billto) {
                //                        document.getElementById('dropBillTo').selectedIndex = i;
                //                    }
                //                }
            }
        }
       
    </script>
    <script type="text/javascript">
        function ttt(t) {
            if (!t.checked) {//uncheck
                var id = $(t).attr('id');
                document.getElementById('txtRowToUnSave').value += id + "||";
            }
            else {
                var id = $(t).attr('id');
                var t = $('#txtRowToUnSave').val();
                document.getElementById('txtRowToUnSave').value = t.replace(id + "||", "");
            }
        }
        
        function ShowExcelData() {
            $get("<%=btnShowUploadResult.ClientID %>").click();
            //            $('#imgLoadingxyz').show();
            //            var options = {
            //                type: 'POST',
            //                url: 'WebService1.asmx/ShowExcelData',
            //                data: '',
            //                contentType: 'application/json; charset=utf-8',
            //                dataType: 'json',
            //                success: function (data, status) {
            //                    if (typeof (data.error) != 'undefined') {
            //                        if (data.error != '') {
            //                            alert("1" + data.error);
            //                        } else {
            //                            alert("2" + data.msg);
            //                        }
            //                    }
            //                },
            //                error: function (data, status, e) {
            //                    alert("3"  + e);
            //                }
            //            };
            //            $.ajax(options);
        }

       
    </script>
    <script>
        //prevent user press F5
        var version = navigator.appVersion;

        function showKeyCode(e) {
            var keycode = (window.event) ? event.keyCode : e.keyCode;

            if ((version.indexOf('MSIE') != -1)) {
                if (keycode == 116) {
                    event.keyCode = 0;
                    alert("You should not press F5 because it will make duplicate data.");
                    event.returnValue = false;
                    return false;
                }
            }
            else {
                if (keycode == 116) {
                    return false;
                }
            }
        }

    </script>
</head>
<body onload="JavaScript:document.body.focus();" onkeydown="return showKeyCode(event)">
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ksdjfl" runat="server">
    </asp:ScriptManager>
    <div style="display: none;">
        <asp:Button ID="btnShowUploadResult" runat="server" OnClick="btnShowUploadResult_Click"
            CausesValidation="false" Text="hidden" />
        <asp:TextBox ID="txtdropBillTo" ClientIDMode="Static" runat="server"></asp:TextBox>
        <asp:TextBox ID="txtlblCusCode" ClientIDMode="Static" runat="server"></asp:TextBox>
        <asp:TextBox ID="txtFileName" ClientIDMode="Static" runat="server"></asp:TextBox>
        <asp:TextBox ID="txtRowToUnSave" runat="server" ClientIDMode="Static" Width="100%"></asp:TextBox>
    </div>
    <div class="Mid">
        <div class="Mid1">
            <div id="Div1">
                <%-- <div>
                    Nội dung bên trái
                </div>--%>
                <div>
                    <div class="TitleCont">
                        Import From Excel
                        <img id='imgLoadingxyz' src='../images/oader-grey.gif' style='display: none' />
                    </div>
                    <!-- DataGrid Start -->
                    <div class="Mid2">
                        <div class="Search2">
                            <table id="newspaper-a">
                                <tbody>
                                    <tr>
                                        <td class="BackGround-gray" colspan="4">
                                            <div>
                                                <table style="width: 100%;">
                                                    <tr>
                                                        <td style="width: 30%;">
                                                            <asp:AsyncFileUpload CssClass="Clear_both" ID="AsyncFileUpload1" runat="server" OnUploadedComplete="AsyncFileUpload1_UploadedComplete"
                                                                OnClientUploadComplete="ShowExcelData" />
                                                        </td>
                                                        <td>
                                                            <asp:Label ID="lblResult" runat="server"></asp:Label>
                                                <input type='button' value="Close" style="width:80px;" class="button Float-right" onclick="javascript:window.close();" />
                                                            <asp:Button ID="btnTemplate" runat="server" CssClass="button Float-right" Text="Template"
                                                                Width="80px" OnClick="btnTemplate_Click" />
                                                            <asp:Button ID="btnReadFile" ClientIDMode="Static" runat="server" Width="80px" CssClass="button Float-right"
                                                                Text="Save" OnClick="btnReadFile_Click" />

                                                        </td>
                                                    </tr>
                                                </table>
                                            </div>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div style="height: 500px; overflow: auto;">
                        <div class="Mid2" id="divData">
                            <table id="newspaper-b" class="tablesorter">
                                <thead>
                                    <tr>
                                        
                                        <th scope="col">
                                        #
                                        </th>
                                        <th scope="col">
                                        </th>
                                        <th scope="col">
                                            Shop Code
                                        </th>
                                        <th scope="col">
                                            Serial No
                                        </th>
                                        <th scope="col">
                                            Model
                                        </th>
                                        <th scope="col">
                                            User Cell
                                        </th>
                                        <th scope="col">
                                            Error
                                        </th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <asp:Literal ID="litData" runat="server"></asp:Literal>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div class="Clear_both">
                    </div>
                </div>
            </div>
        </div>
    </div>
    </form>
</body>
</html>
